﻿package mortal.game.view.ThanksGiving
{
    import com.mui.containers.globalVariable.*;
    import com.mui.controls.*;
    import com.mui.display.*;
    import com.mui.events.*;
    import com.mui.utils.*;
    import extend.language.*;
    import flash.geom.*;
    import mortal.component.window.*;
    import mortal.game.manager.*;
    import mortal.game.manager.window3d.*;
    import mortal.game.resource.*;
    import mortal.game.view.ThanksGiving.data.*;
    import mortal.game.view.ThanksGiving.item.*;
    import mortal.game.view.ThanksGiving.panel.*;
    import mortal.game.view.common.*;
    import mortal.mvc.interfaces.*;

    public class ThanksGivingModule extends BaseWindow
    {
        protected var _leftBg:ScaleBitmap;
        protected var _tabBar:GTabBar2;
        private var _ary:Array;
        protected var _rightPanel:GSprite;
        protected var _rect3d:Rect3DObject;
        private var _rechargeIndex:int = 3;
        private static var _instance:ThanksGivingModule;

        public function ThanksGivingModule(param1:ILayer = null)
        {
            super(LayerManager.windowLayer3D);
            setSize(900, 600);
            this.title = "" + Language.getString(71403);
            return;
        }// end function

        protected function getActive11Ary() : Array
        {
            this._ary = [];
            this._ary.push(new ThanksGivingTabData(ThanksGivingTabData.DuiHuan, ThanksGivingDuiHuanPanel));
            this._ary.push(new ThanksGivingTabData(ThanksGivingTabData.TanBao, ThanksGivingTanBaoPanel));
            this._ary.push(new ThanksGivingTabData(ThanksGivingTabData.Login, ThanksGivingLoginPanel));
            this._ary.push(new ThanksGivingTabData(ThanksGivingTabData.Consum, ThanksGivingConsumPanel));
            this._ary.push(new ThanksGivingTabData(ThanksGivingTabData.Boss, ThanksGivingBossPanel));
            this._ary.push(new ThanksGivingTabData(ThanksGivingTabData.Shop, ThanksGivingShopPanel));
            this._ary.push(new ThanksGivingTabData(ThanksGivingTabData.RedBag, ThanksGivingRedBagPanel));
            return this._ary;
        }// end function

        override protected function createDisposedChildrenImpl() : void
        {
            super.createDisposedChildrenImpl();
            this._leftBg = UIFactory.bg(4, 36, 202, 552, this, ImagesConst.PanelBg);
            this._tabBar = UICompomentPool.getUICompoment(GTabBar2);
            this._tabBar.cellRenderer = ThanksGivingTabCell;
            this._tabBar.gap = 1;
            this._tabBar.cellWidth = 182;
            this._tabBar.cellHeight = 60;
            this._tabBar.direction = GBoxDirection.VERTICAL;
            this._tabBar.x = 10;
            this._tabBar.y = 39;
            this._tabBar.configEventListener(MuiEvent.GTABBAR_SELECTED_CHANGE, this.onSelectChange);
            this.addChild(this._tabBar);
            this._tabBar.dataProvider = this.getActive11Ary();
            this._tabBar.selectIndex = 0;
            this.updatePanel();
            this.checkRw();
            return;
        }// end function

        protected function onSelectChange(event:MuiEvent = null) : void
        {
            this.updatePanel();
            return;
        }// end function

        protected function updatePanel() : void
        {
            if (this._rightPanel)
            {
                this._rightPanel.dispose();
            }
            var _loc_1:* = this._tabBar.dataProvider[this._tabBar.selectIndex];
            this._rightPanel = UIFactory.getUICompoment(_loc_1.className);
            this._rightPanel.createDisposedChildren();
            UIFactory.setObjAttri(this._rightPanel, 211, 37, -1, -1, this);
            if (ThanksGivingTabData.Boss == _loc_1.type)
            {
                if (this._rect3d)
                {
                    Rect3DManager.instance.disposeRect3d(this._rect3d);
                    this._rect3d = null;
                }
            }
            else if (this._rect3d == null)
            {
                this._rect3d = Rect3DManager.instance.registerWindow(true, new Rectangle(0, 0, 0, 0), this);
            }
            return;
        }// end function

        override protected function disposeImpl(param1:Boolean = true) : void
        {
            if (this._rect3d)
            {
                Rect3DManager.instance.disposeRect3d(this._rect3d);
                this._rect3d = null;
            }
            this._leftBg = null;
            this._tabBar.dispose();
            this._tabBar = null;
            this._rightPanel.dispose();
            this._rightPanel = null;
            super.disposeImpl(param1);
            return;
        }// end function

        public function updateConsum() : void
        {
            if (this._rightPanel && this._rightPanel is ThanksGivingConsumPanel)
            {
                (this._rightPanel as ThanksGivingConsumPanel).updateInfo();
            }
            this.checkRw();
            return;
        }// end function

        private function checkRw() : void
        {
            var _loc_1:* = ThanksGivingUtil.getRwIndex();
            var _loc_2:* = this._ary[this._rechargeIndex];
            var _loc_3:* = this._tabBar.itemToCell(_loc_2) as ThanksGivingTabCell;
            if (_loc_1 != -1)
            {
                _loc_3.hasRw(true);
                this._tabBar.selectIndex = this._rechargeIndex;
            }
            else
            {
                _loc_3.hasRw(false);
            }
            return;
        }// end function

        public static function get instance() : ThanksGivingModule
        {
            if (!_instance)
            {
                _instance = new ThanksGivingModule;
            }
            return _instance;
        }// end function

    }
}
